import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Solution {
    static int[] month = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    // static int[] price = {0, 1, 2, 2, 1, 2, 1, 2, 1, 1, 1, 2, 1};
    static int[] price = {0, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1, 2};

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int yearPrice = 0;
        for(int i = 1; i <= 12; i++){
            yearPrice += price[i] * month[i];
        }
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            int year1 = in.nextInt();
            int month1 = in.nextInt();
            int day1 = in.nextInt();
            int year2 = in.nextInt();
            int month2 = in.nextInt();
            int day2 = in.nextInt();
            int ret = 0;
            //先计算年
            for(int i = year1; i < year2; i++){
                if(judge(i)){//判断是否为闰年
                    ret = ret + yearPrice + 1;//闰年二月最后一天赚1元
                }else{
                    ret += yearPrice;
                }
            }
            //再计算月和日
            int ret1 = sum(year1, month1, day1);
            int ret2 = sum(year2, month2, day2);
            ret = ret - ret1 + ret2;
            //加上少算的一天
            ret += price[month1];
            System.out.println(ret);
        }
    }

    public static boolean judge(int year){
        if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return true;
        else return false;
    }

    public static int sum(int y, int m, int d){
        int ret = 0;
        //先计算月
        for(int i = 1; i < m; i++){
            ret += month[i] * price[i];
        }
        //判断是否需要+1
        if(m > 2 && judge(y)){
            ret += 1;
        }
        //再计算日
        ret += d * price[m];
        return ret;
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        long[] fib = new long[100001];
        fib[0] = 1;
        fib[1] = 1;
        int flg = 29;
        for(int i = 2; i < fib.length; i++){
            fib[i] = fib[i-1] + fib[i-2];
            //    System.out.println(fib[i]);
            fib[i] %= 1000000;
        }
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            if(n < flg)  System.out.println(fib[n]);
            else System.out.printf("%06d\n", fib[n]);

        }
    }
    //最长数对链(动归)
    public int findLongestChain1(int[][] pairs) {
        //预处理
        Arrays.sort(pairs, (a, b) ->{
            return a[0] - b[0];
        });
        //创建dp表
        int n = pairs.length;
        int[] dp = new int[n];
        //初始化
        for(int i = 0; i < n; i++){
            dp[i] = 1;
        }
        int ret = 1;
        //填表
        for(int i = 1; i < n; i++){
            for(int j = 0; j < i; j++){
                if(pairs[i][0] > pairs[j][1]){
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            ret = Math.max(ret, dp[i]);
        }
        //返回
        return ret;
    }
    //最长对数链(贪心)
    public int findLongestChain(int[][] pairs) {
        int cur = Integer.MIN_VALUE;
        //排序
        Arrays.sort(pairs, (a, b) -> {
            return a[1] - b[1];
        });
        int ret = 0;
        for(int[] pair : pairs){
            if(cur < pair[0]){
                cur = pair[1];
                ret++;
            }
        }
        return ret;
    }
    //最长定差子序列
    public int longestSubsequence(int[] arr, int difference) {
        //使用hash表进行优化
        Map<Integer, Integer> hash = new HashMap<>();
        int ret = 0;
        for(int k : arr){
            hash.put(k, hash.getOrDefault(k - difference, 0) + 1);
            ret = Math.max(hash.get(k), ret);
        }
        return ret;
    }

    public static void main(String[] args) {
        int[][] pairs = {{-6,9},{1,6},{8,10},{-1,4},{-6,-2},{-9,8},{-5,3},{0,3}};
        Solution solution = new Solution();
        solution.findLongestChain(pairs);
    }
}